package com.yoyo.itravel.dao;

import com.yoyo.itravel.bean.Airline;
import com.yoyo.itravel.bean.PageBean;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.List;

/**
 * 航空公司表相关操作接口【持久层】
 * @Author: liuchaojie
 * @Date 2020/6/16 15:33
 */
@Repository
public interface IAirlineDao {
    /**
     * 增加航空公司
     * @param airline
     * @return
     * @throws SQLException
     */
    @Insert("insert into tb_airline(airlineId, airlineName, icon, phone, address, ontimeRate,alipayUID,registerTime,description) values(#{airline.airlineId},#{airline.airlineName},#{airline.icon},#{airline.phone},#{airline.address},#{airline.ontimeRate},#{airline.alipayUID},#{airline.registerTime},#{airline.description}) ")
    boolean insert(@Param("airline") Airline airline) throws SQLException;

    /**
     * 根据airlineId删除航空公司
     * @param airlineId
     * @return
     * @throws SQLException
     */
    @Delete("delete from tb_airline where airlineId=#{airlineId}")
    boolean deleteByAirlineId(String airlineId) throws SQLException;

    /**
     * 查询所有航空公司
     * @return
     * @throws SQLException
     */
    @Select("select * from tb_airline")
    List<Airline> selectAll() throws SQLException;

    /**
     * 根据airlineId查询航空公司
     * @return
     * @throws SQLException
     */
    @Select("select * from tb_airline where airlineId=#{airlineId}")
    Airline selectByAirlineId(String airlineId) throws SQLException;

    /**
     * 通过airlineId修改航空公司信息
     * @param airline
     * @return
     * @throws SQLException
     */
    @Update("update tb_airline set airlineName=#{airline.airlineName},icon=#{airline.icon}, phone=#{airline.phone}, address=#{airline.address}, ontimeRate=#{airline.ontimeRate},alipayUID=#{airline.alipayUID},registerTime=#{airline.registerTime},description=#{airline.description}where airlineId=#{airline.airlineId}")
    int change(@Param("airline") Airline airline) throws SQLException;

    /**
     * 根据airlineId修改准点率
     * @param ontimeRate
     * @return
     * @throws SQLException
     */
    @Update("update tb_airline set ontimeRate=#{ontimeRate} where airlineId=#{airlineId}")
    int changeOnTimeRate(@Param("airlineId") String airlineId, @Param("ontimeRate") Double ontimeRate)throws SQLException;

    // TODO
    List<Airline> selectAirlineByPage(PageBean pageBean) throws SQLException;

    // TODO
    Integer totalCount() throws SQLException;
}
